package org.jeecg.modules.inventoryPt.controller;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.Inventory.entity.Inventory;
import org.jeecg.modules.Inventory.entity.ReportInventoryVO;
import org.jeecg.modules.Inventory.service.IInventoryService;
import org.jeecg.modules.basicSku.entity.BasicSku;
import org.jeecg.modules.basicSku.service.IBasicSkuService;
import org.jeecg.modules.basicSkuPt.entity.BasicSkuPt;
import org.jeecg.modules.basicSkuPt.service.IBasicSkuPtService;
import org.jeecg.modules.checkInventory.entity.CheckInventory;
import org.jeecg.modules.checkInventory.service.ICheckInventoryService;
import org.jeecg.modules.checkInventoryPt.entity.CheckInventoryPt;
import org.jeecg.modules.checkInventoryPt.service.ICheckInventoryPtService;
import org.jeecg.modules.dataLog.entity.DataLog;
import org.jeecg.modules.dataLog.service.IDataLogService;
import org.jeecg.modules.inOrder.service.IInOrderService;
import org.jeecg.modules.inOrderPt.entity.InOrderPt;
import org.jeecg.modules.inOrderPt.entity.InOrderZiPt;
import org.jeecg.modules.inOrderPt.entity.PtType;
import org.jeecg.modules.inOrderPt.service.IInOrderPtService;
import org.jeecg.modules.inOrderPt.service.IInOrderZiPtService;
import org.jeecg.modules.inventoryPt.entity.InventoryPt;
import org.jeecg.modules.inventoryPt.entity.ReportInventoryPtVO;
import org.jeecg.modules.inventoryPt.service.IInventoryPtService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.operationLog.entity.OperationLog;
import org.jeecg.modules.operationLog.service.IOperationLogService;
import org.jeecg.modules.outOrder.entity.OutOrder;
import org.jeecg.modules.outOrder.entity.OutOrderZi;
import org.jeecg.modules.outOrder.service.IOutOrderService;
import org.jeecg.modules.outOrderPt.entity.OutOrderPt;
import org.jeecg.modules.outOrderPt.entity.OutOrderZiPt;
import org.jeecg.modules.outOrderPt.service.IOutOrderPtService;
import org.jeecg.modules.outOrderPt.service.IOutOrderZiPtService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: PT库存表
 * @Author: jeecg-boot
 * @Date:   2024-07-24
 * @Version: V1.0
 */
@Api(tags="PT库存表")
@RestController
@RequestMapping("/inventoryPt/inventoryPt")
@Slf4j
public class InventoryPtController extends JeecgController<InventoryPt, IInventoryPtService> {
	@Autowired
	private IInventoryPtService inventoryPtService;
	 @Autowired
	 private ICheckInventoryPtService checkInventoryPtService;
	 @Autowired
	 private IDataLogService dataLogService;
	 @Autowired
	 private IOperationLogService operationLogService;
	 @Autowired
	 private IBasicSkuPtService basicSkuPtService;
	 @Autowired
	 private IInOrderPtService inOrderPtService;
	 @Autowired
	 private IInOrderZiPtService inOrderZiPtService;
	 @Autowired
	 private IOutOrderPtService outOrderPtService;
	 @Autowired
	 private IOutOrderZiPtService outOrderZiPtService;
	 @Value("${jeecg.path.upload}")
	 private String upLoadPath;
	/**
	 * 分页列表查询
	 *
	 * @param inventoryPt
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "PT库存表-分页列表查询")
	@ApiOperation(value="PT库存表-分页列表查询", notes="PT库存表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(InventoryPt inventoryPt,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		String location = inventoryPt.getLocation();
		inventoryPt.setLocation(null);
		QueryWrapper<InventoryPt> queryWrapper = QueryGenerator.initQueryWrapper(inventoryPt, req.getParameterMap());
		if (location != null && !location.isEmpty()) {
			queryWrapper.like("location", location);
		}
		queryWrapper.eq("status", 0);
		Page<InventoryPt> page = new Page<InventoryPt>(pageNo, pageSize);
		IPage<InventoryPt> pageList = inventoryPtService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	 @GetMapping(value = "/skuList")
	 public Result<?> skuList(InventoryPt inventoryPt,
							  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
							  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
							  HttpServletRequest req) {
		 QueryWrapper<InventoryPt> queryWrapper = QueryGenerator.initQueryWrapper(inventoryPt, req.getParameterMap());
		 queryWrapper.select("id","customer_code","customer_name"
				 ,"sku_code","sku_name","back_num","brand"
				 ,"SUM(number) AS number","source","length","width"
				 ,"height","weight");
		 queryWrapper.groupBy("sku_code");
		 queryWrapper.eq("status", 0);
		 Page<InventoryPt> page = new Page<InventoryPt>(pageNo, pageSize);
		 IPage<InventoryPt> pageList = inventoryPtService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 @GetMapping(value = "/locationList")
	 public Result<?> locationList(InventoryPt inventoryPt,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		 String location = inventoryPt.getLocation();
		 inventoryPt.setLocation(null);
		 QueryWrapper<InventoryPt> queryWrapper = QueryGenerator.initQueryWrapper(inventoryPt, req.getParameterMap());
		 queryWrapper.select("id","customer_code","customer_name"
				 ,"sku_code","sku_name","back_num","brand"
				 ,"SUM(number) AS number","source","length","width","customer_sku_code"
				 ,"height","weight","location");
		 if (location != null && !location.isEmpty()) {
			 queryWrapper.like("location", location);
		 }
		 queryWrapper.eq("status", 0);
		 queryWrapper.groupBy("sku_code", "location");
		 Page<InventoryPt> page = new Page<InventoryPt>(pageNo, pageSize);
		 IPage<InventoryPt> pageList = inventoryPtService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 @PostMapping(value = "/createCheck")
	 public Result<?> createCheck(@RequestBody List<InventoryPt> inventories) {
		 List<CheckInventoryPt> list = new ArrayList<>();
		 for (InventoryPt inventory : inventories) {
			 CheckInventoryPt checkInventory = new CheckInventoryPt();
			 checkInventory.setSkuCode(inventory.getSkuCode()).setNumber(inventory.getNumber())
					 .setLocation(inventory.getLocation()).setStatus(1).setInventoryId(inventory.getId());
			 list.add(checkInventory);
		 }
		 LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 OperationLog operationLog = new OperationLog();
		 operationLog.setOperationTime(new Date()).setOperationType("生成盘点单").setOperator(user.getRealname());
		 checkInventoryPtService.saveBatch(list);
		 operationLogService.save(operationLog);
		 return Result.OK("生成成功!", null);
	 }
	 @PostMapping(value = "/createOutOrder")
	 public Result<?> createOutOrder(@RequestParam(name="ids",required=true) String ids) {
		 List<InventoryPt> inventories = inventoryPtService.listByIds(Arrays.asList(ids.split(",")));
		 OutOrderPt outOrder = new OutOrderPt();
		 outOrder.setOutTime(new Date());
		 List<OutOrderZiPt> list = new ArrayList<>();
		 for (InventoryPt inventory : inventories) {
			 OutOrderZiPt outOrderZi = new OutOrderZiPt();
			 outOrderZi.setNumber(inventory.getNumber())
					 .setSkuName(inventory.getSkuName())
					 .setCustomer(inventory.getCustomerName())
					 .setLocation(inventory.getLocation())
					 .setInventoryId(inventory.getId())
					 .setInTime(inventory.getInTime())
					 .setSkuCode(inventory.getSkuCode())
					 .setInventory(inventory.getNumber());
			 list.add(outOrderZi);
		 }
		 outOrderPtService.saveMain(outOrder, list);
		 return Result.OK("生成成功!", null);
	 }
	 @RequestMapping(value = "/skuExportXls")
	 public ModelAndView skuExportXls(HttpServletRequest request, InventoryPt inventoryPt) {
		 // Step.1 组装查询条件
		 QueryWrapper<InventoryPt> queryWrapper = QueryGenerator.initQueryWrapper(inventoryPt, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 queryWrapper.select("id","customer_code","customer_name"
				 ,"sku_code","sku_name","back_num","brand"
				 ,"SUM(number) AS number","source","length","width","customer_sku_code"
				 ,"height","weight");
		 queryWrapper.eq("status", 0);
		 queryWrapper.groupBy("sku_code");
		 // Step.2 获取导出数据
		 List<InventoryPt> pageList = inventoryPtService.list(queryWrapper);
		 List<InventoryPt> exportList = null;
		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }
		 List<ReportInventoryPtVO> reportInventoryVOList = exportList.stream()
				 .map(ReportInventoryPtVO::new)
				 .collect(Collectors.toList());
		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "库存表"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, ReportInventoryPtVO.class);
		 //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		 ExportParams  exportParams=new ExportParams("库存表" + "报表", "导出人:" + sysUser.getRealname(), "库存表");
		 exportParams.setImageBasePath(upLoadPath);
		 //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		 mv.addObject(NormalExcelConstants.PARAMS,exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, reportInventoryVOList);
		 return mv;
	 }

	 @RequestMapping(value = "/locationExportXls")
	 public ModelAndView locationExportXls(HttpServletRequest request, InventoryPt inventoryPt) {
		 // Step.1 组装查询条件
		 QueryWrapper<InventoryPt> queryWrapper = QueryGenerator.initQueryWrapper(inventoryPt, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 queryWrapper.select("id","customer_code","customer_name"
				 ,"sku_code","sku_name","back_num","brand"
				 ,"SUM(number) AS number","source","length","width"
				 ,"height","weight","location");
		 queryWrapper.eq("status", 0);
		 queryWrapper.groupBy("sku_code", "location");
		 // Step.2 获取导出数据
		 List<InventoryPt> pageList = inventoryPtService.list(queryWrapper);
		 List<InventoryPt> exportList = null;
		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }
		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "库存表"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, InventoryPt.class);
		 //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		 ExportParams  exportParams=new ExportParams("库存表" + "报表", "导出人:" + sysUser.getRealname(), "库存表");
		 exportParams.setImageBasePath(upLoadPath);
		 //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		 mv.addObject(NormalExcelConstants.PARAMS,exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
	 }

	 private String getId(InventoryPt item) {
		 try {
			 return PropertyUtils.getProperty(item, "id").toString();
		 } catch (Exception e) {
			 e.printStackTrace();
			 return null;
		 }
	 }

	 @AutoLog(value = "库存表-测试")
	 @ApiOperation(value="库存表-测试", notes="库存表-测试")
	 @GetMapping(value = "/test")
	 public Result<?> test() {
		 List<InventoryPt> inventories = inventoryPtService.list();
		 List<BasicSkuPt> list = basicSkuPtService.list();
		 Map<String, BasicSkuPt> map = list.stream()
				 .collect(Collectors.toMap(BasicSkuPt::getSkuCode, Function.identity()));
		 for (InventoryPt inventory : inventories) {
			 String skuCode = inventory.getSkuCode();
			 if (map.containsKey(skuCode)) {
				 BasicSkuPt sku = map.get(skuCode);
				 inventory.setSkuName(sku.getSkuName());
				 inventory.setBrand(sku.getBrand());
			 }
		 }
		 inventoryPtService.updateBatchById(inventories);
		 return Result.OK();
	 }

	 /**
	 *   添加
	 *
	 * @param inventoryPt
	 * @return
	 */
	@AutoLog(value = "PT库存表-添加")
	@ApiOperation(value="PT库存表-添加", notes="PT库存表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody InventoryPt inventoryPt) {
		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		DataLog dataLog = new DataLog();
		dataLog.setOperator(user.getRealname()).setOperationTime(new Date())
				.setOperationType("新增").setOperationClass("库存表")
				.setUpdated(inventoryPt.toString());
		inventoryPtService.save(inventoryPt);
		dataLogService.save(dataLog);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param inventoryPt
	 * @return
	 */
	@AutoLog(value = "PT库存表-编辑")
	@ApiOperation(value="PT库存表-编辑", notes="PT库存表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody InventoryPt inventoryPt) {
		InventoryPt byId = inventoryPtService.getById(inventoryPt.getId());
		if (byId == null) {
			return Result.error("未找到对应数据");
		}
		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		DataLog dataLog = new DataLog();
		dataLog.setOperator(user.getRealname()).setOperationTime(new Date())
				.setOperationType("编辑").setOperationClass("库存表")
				.setOriginal(byId.toString()).setUpdated(inventoryPt.toString());
		inventoryPtService.updateById(inventoryPt);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "PT库存表-通过id删除")
	@ApiOperation(value="PT库存表-通过id删除", notes="PT库存表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		InventoryPt byId = inventoryPtService.getById(id);
		if (byId == null) {
			return Result.error("未找到对应数据");
		}
		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		DataLog dataLog = new DataLog();
		dataLog.setOperator(user.getRealname()).setOperationTime(new Date())
				.setOperationType("删除").setOperationClass("库存表")
				.setOriginal(byId.toString());
		inventoryPtService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "PT库存表-批量删除")
	@ApiOperation(value="PT库存表-批量删除", notes="PT库存表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		List<String> list = Arrays.asList(ids.split(","));
		List<InventoryPt> inventories = inventoryPtService.listByIds(list);
		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		Date date = new Date();
		List<DataLog> dataLogs = new ArrayList<>();
		for (InventoryPt inventory : inventories) {
			DataLog dataLog = new DataLog();
			dataLog.setOperator(user.getRealname()).setOperationTime(date)
					.setOperationType("删除").setOperationClass("库存表")
					.setOriginal(inventory.toString());
			dataLogs.add(dataLog);
		}
		this.inventoryPtService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "PT库存表-通过id查询")
	@ApiOperation(value="PT库存表-通过id查询", notes="PT库存表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		InventoryPt inventoryPt = inventoryPtService.getById(id);
		if(inventoryPt==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(inventoryPt);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param inventoryPt
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, InventoryPt inventoryPt) {
        return super.exportXlsStatus(request, inventoryPt, InventoryPt.class, "PT库存表");
    }

	 /**
	  * 导出excel
	  *
	  * @param request
	  * @param inventoryPt
	  */
	 @RequestMapping(value = "/yueduExportXls")
	 public ModelAndView yueduExportXls(HttpServletRequest request, InventoryPt inventoryPt) {
		 String[] split = inventoryPt.getInDate().split("-");
		 String[] split1 = split[0].split("\"");
		 List<String> inOrderPts = inOrderPtService.getByYear(split1[1],split[1]).stream().map(InOrderPt::getId).collect(Collectors.toList());
		 List<InOrderZiPt> inOrderZiPtList = inOrderZiPtService.list(new LambdaQueryWrapper<InOrderZiPt>().in(InOrderZiPt::getInOrderId, inOrderPts));
		 List<String> outOrderPts = outOrderPtService.getByYear(split1[1],split[1]).stream().map(OutOrderPt::getId).collect(Collectors.toList());
		 List<OutOrderZiPt> outOrderZiPtList = outOrderZiPtService.list(new LambdaQueryWrapper<OutOrderZiPt>().in(OutOrderZiPt::getOutOrderId, outOrderPts));
		 List<InventoryPt> inventoryPts = inventoryPtService.getByYear(split1[1],split[1]);
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 Map<String, List<PtType>> map = new HashMap<>();
		 inOrderZiPtList.forEach(item->{
			 PtType ptType = new PtType();
			 ptType.setType(0);
			 ptType.setSkuCode(item.getSkuCode());
			 ptType.setClient(item.getCustomerName());
			 ptType.setClientCode(item.getCustomerCode());
			 ptType.setNumber(item.getNumber());
			 List<PtType> ptTypes = map.get(item.getSkuCode());
			 if (ptTypes != null&& !ptTypes.isEmpty()){
				 ptTypes.add(ptType);
				 map.put(item.getSkuCode(),ptTypes);
			 }else {
				 List<PtType> ptTypeList = new ArrayList<>();
				 ptTypeList.add(ptType);
				 map.put(item.getSkuCode(),ptTypeList);
			 }
		 });
		 outOrderZiPtList.forEach(item->{
			 BasicSkuPt basicSkuPt = basicSkuPtService.list(new LambdaQueryWrapper<BasicSkuPt>().eq(BasicSkuPt::getCustomerSkuCode, item.getCustomerSkuCode())).get(0);
			 PtType ptType = new PtType();
			 ptType.setType(1);
			 ptType.setSkuCode(basicSkuPt.getSkuCode());
			 ptType.setClient(item.getCustomer());
			 ptType.setClientCode(item.getCustomerSkuCode());
			 ptType.setNumber(item.getNumber());
			 List<PtType> ptTypes = map.get(basicSkuPt.getSkuCode());
			 if (ptTypes != null&& !ptTypes.isEmpty()){
				 ptTypes.add(ptType);
				 map.put(basicSkuPt.getSkuCode(),ptTypes);
			 }else {
				 List<PtType> ptTypeList = new ArrayList<>();
				 ptTypeList.add(ptType);
				 map.put(basicSkuPt.getSkuCode(),ptTypeList);
			 }
		 });
		 inventoryPts.forEach(item->{
			 PtType ptType = new PtType();
			 ptType.setType(2);
			 ptType.setSkuCode(item.getSkuCode());
			 ptType.setClient(item.getCustomerName());
			 ptType.setClientCode(item.getCustomerCode());
			 ptType.setNumber(item.getNumber());
			 List<PtType> ptTypes = map.get(item.getSkuCode());
			 if (ptTypes != null&& !ptTypes.isEmpty()){
				 ptTypes.add(ptType);
				 map.put(item.getSkuCode(),ptTypes);
			 }else {
				 List<PtType> ptTypeList = new ArrayList<>();
				 ptTypeList.add(ptType);
				 map.put(item.getSkuCode(),ptTypeList);
			 }
		 });
		 for (String key : map.keySet()) {
			 // 通过键获取对应的值

		 }
		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "PT库存月度表"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, InventoryPt.class);
		 //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		 ExportParams  exportParams=new ExportParams("PT库存月度表" + "报表", "导出人:" + sysUser.getRealname(), "PT库存月度表");
		 exportParams.setImageBasePath(upLoadPath);
		 //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		 mv.addObject(NormalExcelConstants.PARAMS,exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, inventoryPts);
		 return mv;
	 }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, InventoryPt.class);
    }

	@GetMapping("/m/getBySku")
	 public Result<?> getBySku(@RequestParam(name = "skuCode") String skuCode) {
		LambdaQueryWrapper<InventoryPt> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(InventoryPt::getSkuCode, skuCode);
		List<InventoryPt> list = inventoryPtService.list(wrapper);
		if (list.isEmpty()){
			return Result.error("未找到PT品【"+skuCode+"】品番的库存");
		}
		return Result.OK(list);
	}

}
